package com.itheima.web; /**
 * @author Xiao
 * @date 2021/9/5
 */

import com.itheima.pojo.User;
import com.itheima.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/selectUserServlet")
public class SelectUserServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收用户名
        String username = request.getParameter("username");
        //逻辑代码 --》 查询数据库是否存在该用户名
        User user = userService.selectByUname(username);
        boolean flag = user == null;
        //响应给浏览器 --》 直接写出
        response.getWriter().write(String.valueOf(flag));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
